#proevolytx@gmail.com
#2012/9/15

class Parser:
    def __init__(s, lex):
        s.lex = lex
        s.index = 0
        if len(lex) > 0:
            s.la = s.lex[0]
        else:
            s.la = None
        s.out = ""

    def nextlex(s):
        if s.index < len(s.lex):
            s.index += 1
        if s.index < len(s.lex):
            s.la = s.lex[s.index]
        else:
            s.la = None

    def match(s, token):
        if s.la[:len(token)] != token:
            raise Exception(str(token) + " expected, " + str(s.la) + " instead")
        else:
            s.nextlex()
